/******************************************************************************
 * FileName:    gwin_protocol_task.h
 * Desc:        协议
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef __GWIN_PROTOCOL_H__
#define __GWIN_PROTOCOL_H__


/*-------------------------- Includes ---------------------------------------*/
#include "gwin_global_data.h"
#include "gwin_global_config.h"


/*-------------------------- Macro Definitions ------------------------------*/
#define GWIN_PROT_RX_IRQ                                ( 0 )                           // 中断接收


/*-------------------------- Type Declarations ------------------------------*/
/**
 * @brief 消息
 */
typedef struct
{
    uint16_t type;
    uint16_t subtype;
    union
    {
        uint32_t param;
        struct
        {
            uint8_t *data;
            uint16_t len;
            uint16_t reserve;
        };
    };
}gwin_protocol_task_msg_t;


/**
 * @brief 数据来源
 */
typedef enum
{
    PROTOCOL_TASK_DATA_WAY_NONE,
    PROTOCOL_TASK_DATA_WAY_MCU,
}gwin_protocol_data_way_t;

/**
 * @brief 消息类型
 */
typedef enum
{
    PROTOCOL_TASK_MSG_TYPE_NONE,
    PROTOCOL_TASK_MSG_TYPE_TASK_START,
    PROTOCOL_TASK_MSG_TYPE_TIMER,
    PROTOCOL_TASK_MSG_TYPE_RECV,
    PROTOCOL_TASK_MSG_TYPE_SEND,
}gwin_protocol_task_msg_type_t;

/**
 * @brief 定时器消息子类型
 */
typedef enum
{
    PROTOCOL_TASK_MSG_TIMER_SUBTYPE_NONE,
    PROTOCOL_TASK_MSG_TIMER_SUBTYPE_UART_RX,
    PROTOCOL_TASK_MSG_TIMER_SUBTYPE_UART_TX,
    PROTOCOL_TASK_MSG_TIMER_SUBTYPE_BLE_TX,
}gwin_protocol_task_msg_timer_subtype_t;


/**
 * @brief 协议 命令
 */
typedef enum _gwin_protocol_cmd
{
    GWIN_PROT_CMD_NETWORK                   = 0x43,             // 网络

    // 研发预留用
    GWIN_PROT_CMD_RESET_ALL_FORCE           = 0xE0,             // 强制复位所有参数（研发预留接口，防止错误，直接响应）

    GWIN_PROT_CMD_TEMP_ACTION               = 0xF4,             // 动作
}gwin_protocol_cmd_t;
#define GWIN_PROT_CMD_PAYLOAD_LEN_GET       ( 1 )               // 数据长度为1，默认是查询
#define GWIN_PROT_CMD_NO_CHANGE             ( 0xFF)             // 不调整（通用）


/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
void gwin_protocol_task_init(void);
uint8_t gwin_send_msg_to_protocol_task(gwin_protocol_task_msg_t *p_msg);

void gwin_protocol_data_recv(uint8_t way, uint8_t *data, uint16_t len);
void gwin_protocol_data_send_mcu(uint32_t type);


#endif // __GWIN_PROTOCOL_H__


/*-------------------------- END OF FILE ------------------------------------*/

